package com.example.security.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.Enumeration;


/**
 * @author LiYuhang
 * @version 0.1
 * @application
 */
@RestController
@RequestMapping("/userInfo")
public class HelloController {

    @Value("${server.port}")
    private String serverPort;
    @GetMapping("/userList")
    public String userList() {
        return "userList";
    }

    @GetMapping("/loadBalence")
    public String loadBalence() {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        HttpSession session = request.getSession();
        String string = new Date().toString();
        session.setAttribute(string,string);
        Enumeration<String> names = session.getAttributeNames();
        while(names.hasMoreElements()){
            String name = names.nextElement().toString();
            System.out.println(name+":"+session.getAttribute(name));
        }
            // String id=request.getS
        return serverPort;
    }


    @GetMapping("/userAdd")
    public String userAdd() {
        return "userAdd";
    }

    @GetMapping("/userDel")
    public String userDel() {
        return "userDel";
    }

    @GetMapping("/userView")
    public String userView() {
        return "userView";
    }

    @GetMapping("/hello")
    public String hello() {
        return "hello";
    }

}
